package cn.ylg.com.baisibudeijie.pro.login.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import cn.ylg.com.baisibudeijie.R;
import cn.ylg.com.baisibudeijie.dao.AccountDao;
import cn.ylg.com.baisibudeijie.pro.base.view.BaseActivity;
import cn.ylg.com.baisibudeijie.pro.login.view.fragment.SignInFra;
import cn.ylg.com.baisibudeijie.pro.login.view.fragment.SignUpFra;

/**
 * Created by MyPC on 2016/10/21.
 */
public class LoginActivity extends BaseActivity {
    //登录
    public static final String TAG_LOGO = "logo";
    //登录
    public static final String TAG_SIGN_IN = "sign_in";
    //注册
    public static final String TAG_SIGN_UP = "sign_up";
    //填充信息
    public static final String TAG_FILL_INFO = "fill_info";

    public static final String ENTER_KEY = "enter";
    public static final int ENTER_FIRST = 0;
    public static final int ENTER_LOGINED = 1;
    public static final int ENTER_SIGN_IN = 2;
    public static final int ENTER_SIGN_UP = 3;
    public static final int ENTER_FILL_INFO = 4;


    private FragmentManager fm;
    private String currentTag;
    private Fragment currentFra;
    private AccountDao dao;
    private int enterFlag = 0;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_login);
        fm = getSupportFragmentManager();
        enterFlag = getIntent().getIntExtra(ENTER_KEY,ENTER_FIRST);
        //如果是第一次登录的话;
        if (enterFlag==ENTER_FIRST){
            go2SignUp();
        }
    }

    public void go2SignIn(){
        Fragment fragment = fm.findFragmentByTag(TAG_SIGN_IN);
        if (fragment==null){
            fragment = new SignInFra();
        }
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.container,fragment, TAG_SIGN_IN);
        ft.addToBackStack(TAG_SIGN_IN);
        ft.commit();
    }

    public void go2SignUp(){
        Fragment fragment = fm.findFragmentByTag(TAG_SIGN_UP);
        if (fragment==null){
            fragment = new SignUpFra();
        }
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.container,fragment,TAG_SIGN_UP);
        ft.addToBackStack(TAG_SIGN_UP);
        ft.commit();
    }
    public void go2FillInfo(){

    }
//    private void signUp(){
//        AsyncHttpClient client = new AsyncHttpClient();
//        String url = "";
//        client.post(this, url, null, new TextHttpResponseHandler() {
//            @Override
//            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//
//            }
//
//            @Override
//            public void onSuccess(int statusCode, Header[] headers, String responseString) {
//
//            }
//        });
//    }
}
